{include file="public/head" /}

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">后台管理</a>
        <a href="">物业管理系统</a>
        <a>
          <cite>发票列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so"  method="get" action="{url('invoiceList')}">

            <div class="layui-input-inline">
                <select name="community_id" lay-filter="community_id" id="community_id">
                    <option value="">所属小区</option>
                    {foreach $communitylist as $name}
                    <option value="{$name.community_id}" {if isset($community_id)}{if $community_id == $name.community_id}selected{/if}{/if}>{$name.community_name}</option>
                    {/foreach}
                </select>
            </div>

            <div class="layui-input-inline">
                <select name="invoice_type">
                    <option value="">发票类型</option>
                    <option value="1" {if isset($invoice_type)}{if $invoice_type == '1'}selected{/if}{/if}>蓝票</option>
                    <option value="2" {if isset($invoice_type)}{if $invoice_type == '2'}selected{/if}{/if}>红票</option>
                    <option value="3" {if isset($invoice_type)}{if $invoice_type == '3'}selected{/if}{/if}>未开票</option>

                </select>
            </div>


            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>



        <button class="layui-btn" onclick="x_admin_show('发票填开','{:url(\'invoicefilling\')}',800,500)"><i class="layui-icon"></i>发票填开</button>

        <button class="layui-btn layui-btn-normal" onclick="invoiceExportExcel('{$export}')"><i class="layui-icon"></i>批量导出</button>

        <span style="color:red"> *用于线下收款缴费项目，需要手工填写开票交付</span>
        {if $Think.session.usertype=="0"}

        {/if}
        <span class="x-right" style="line-height:40px">&nbsp; 共有数据： {$number}  条</span>
    </xblock>
    <table class="layui-table"  id="table">
        <thead>
        <tr>

            <th style="text-align: center; font-size: 16px;">小区名称</th>
            <th style="text-align: center; font-size: 16px;">发票抬头</th>
            <th style="text-align: center; font-size: 16px;">税号</th>
            <th style="text-align: center; font-size: 16px;">含税金额</th>
            <th style="text-align: center; font-size: 16px;">发票号码</th>
            <th style="text-align: center; font-size: 16px;">发票类型</th>

            <th style="text-align: center; font-size: 16px;">开票时间</th>

            <th style="text-align: center; font-size: 16px;width: 30%">操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $list as $val}
        <tr>

            <td style="text-align: center;">{$val.community_name}</td>
            <td style="text-align: center;">{$val.buyerName}</td>
            <td style="text-align: center;">{$val.buyerTaxNum}</td>
            <td style="text-align: center;">￥{$val.pay_money}</td>
            <td style="text-align: center;">{$val.invoiceNum}</td>

            <td style="text-align: center;">
                {if $val.invoice_type == '1'}
                蓝票
                {elseif $val.invoice_type == '2'}
                <span style="color:red">红票</span>
                {else}
                {/if}
            </td>

            <td style="text-align: center;">{$val.invoice_time}</td>
            <td class="td-manage" style="text-align: center;">
                {if $val.invoice_type=="3"}
                <button class="layui-btn" onclick="invoice('{$val.id}')">开票</button>
                {if $Think.session.usertype=="0"}
                <button class="layui-btn" onclick="x_admin_show('修改','{:url(\'invoiceEdit\')}?id={$val.id}',700,500)">修改</button>
                {/if}
                {/if}
                {if $val.invoice_type=="1"}
                <button class="layui-btn" onclick="x_admin_show('查看发票','{:url(\'CheckInvoice\')}?id={$val.id}',900,700)">查看</button>
                {/if}
                {if $val.invoice_type=="2"}
                <button class="layui-btn" onclick="x_admin_show('查看发票','{:url(\'CheckInvoiceRed\')}?id={$val.id}',900,700)">查看</button>
                {/if}

                <button class="layui-btn layui-btn-normal" onclick="x_admin_show('开票内容','{:url(\'details\')}?id={$val.id}',900,700)">开票内容</button>




                {if $val.invoice_type == 1}
                <button class="layui-btn  layui-btn-normal" onclick="x_admin_show('交付','{:url(\'delivery\')}?id={$val.id}',600,400)">交付</button>

                <button class="layui-btn  layui-btn-danger" onclick="cancellation('{$val.id}')">冲红</button>
                {/if}

                {if $val.invoice_type=="3"}

                <button class="layui-btn layui-btn-danger" onclick="del('{$val.id}')">删除</button>
                {/if}

            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
    <div class="page">
        <div>
            {$list->render()}
        </div>
    </div>

</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
            ,format: 'yyyy-MM-dd HH:mm:ss'
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
            ,format: 'yyyy-MM-dd HH:mm:ss'
        });
    });

    //批量导出
    function invoiceExportExcel(exportid){

        var url = "{:url('invoiceExportExcel')}?&export=" + exportid;
        console.log(url);
        layer.open({
            type: 2,
            title: '批量导出账单',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '95%'],
            content: url //iframe的url
        });
    }
    function cancellation(id){
        layer.confirm('是否确定冲红?', function(){
            $.post('{:url("cancellation")}', { id: id}, function(r){
                location.reload();
                return;
                if (r.success) {
                    layer.alert(r.success, {icon: 6},function () {
                        location.reload()
                    });
                }else{
                    layer.alert(r.error, {icon: 2},function () {
                        location.reload()
                    });

                }
            })
        })

    }
    function invoice(id){


        $.post('{:url("invoice")}', { id: id}, function(r){
            if (r.success) {
                layer.alert(r.success, {icon: 6},function () {
                    location.reload()
                });
            }else{
                layer.alert(r.error, {icon: 2},function () {
                    location.reload()
                });

            }
        })
    }
    function del(id){
        layer.confirm('删除后无法恢复，确定要删除吗?', function(){
            $.post('{:url("del")}', { id: id}, function(r){
                if (r.success) {
                    layer.alert(r.success, {icon: 6},function () {
                        location.reload()
                    });
                }else{
                    layer.alert(r.error, {icon: 2},function () {
                        location.reload()
                    });

                }
            })
        })

    }

</script>
<!-- 多条件查询 -->

<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>